import { BasicPageSearchParams } from "/@/api/model/baseModel";
import { defHttp } from '/@/utils/http/axios';
import axios from 'axios';


// 项目管理->委托依据->委托依据明细
enum Api {
  list = '/CheckReasonDetail/list',
  view = '/CheckReasonDetail/view/',
  add = '/CheckReasonDetail/add',
  update = '/CheckReasonDetail/update',
  del = '/CheckReasonDetail/del/',
  getDetailList = '/CheckReasonDetail/getDetailList/',
  export = '/CheckReasonDetail/export/',
}


export const list = (params?: any) => {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<any>;
  return defHttp.post<any>({ url: Api.list, params: queryParam });
};

export const view = (id?: number) => {
  return defHttp.get<any>({ url: Api.view + id });
};

export const add = (params) =>
  defHttp.post<any>({ url: Api.add, params });

export const update = (params) =>
  defHttp.post<any>({ url: Api.update, params });

export const del = (id?: number) =>
  defHttp.post<any>({ url: Api.del + id });

export const getDetailList = (params?: any) => {
  return defHttp.get<any>({ url: Api.getDetailList + params.reasonId });
};

// 导出数据，直接调用不行，需要直接在页面调用：
// location.href = '/check-api/CheckReasonDetail/export/' + props.reasonId;
export const exportData = (params?: any) => {
  return defHttp.get<any>({ url: Api.export + params.reasonId });
};


//导出一
export const exportExcel = (params) => {
  axios.get(Api.export + params.reasonId).then(res => {
    let blob = new Blob([res.data], {
      type: 'application/vnd.ms-excel',
    });
    let downloadElement = document.createElement('a');
    let href = window.URL.createObjectURL(blob); //创建下载的链接
    downloadElement.href = href;
    downloadElement.download = '委托依据明细.xlsx'; //下载后文件名
    document.body.appendChild(downloadElement);
    downloadElement.click(); //点击下载
    document.body.removeChild(downloadElement); //下载完成移除元素
    window.URL.revokeObjectURL(href); //释放掉blob对象
  })
};